package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.GfxyTQnjsjkbs;

import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.GfxyTQnjsjkbsMapper;
import com.gfxy.modules.items.service.IGfxyTQnjsjkbsService;
import com.gfxy.modules.items.vo.*;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 青年教师讲课比赛
 * @Author: jeecg-boot
 * @Date:   2021-10-02
 * @Version: V1.0
 */
@Service
public class GfxyTQnjsjkbsServiceImpl extends AbstractProjectServiceImpl<GfxyTQnjsjkbsMapper, GfxyTQnjsjkbs> implements IGfxyTQnjsjkbsService {

	protected int memberCellNum = 4;

	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	@Override
	protected GfxyTQnjsjkbs getOneProject(Row row) {

		String date = ExcelUtil.formatCell(row.getCell(0));

		String classess  = ExcelUtil.formatCell(row.getCell(1));
		String award= ExcelUtil.formatCell(row.getCell(2));
		String projectName = ExcelUtil.formatCell(row.getCell(3));
		//String stepName = ExcelUtil.formatCell(row.getCell(4));

		GfxyTQnjsjkbs gfxyTQnjsjkbs = new GfxyTQnjsjkbs();

		gfxyTQnjsjkbs.setDate(date);
		gfxyTQnjsjkbs.setClassess(translateClassess(classess));
		gfxyTQnjsjkbs.setAward(translateAward(award));
		gfxyTQnjsjkbs.setProjectName(projectName);
		gfxyTQnjsjkbs.setIsPass(0);
		gfxyTQnjsjkbs.setTotalScore(this.getTotalScore(gfxyTQnjsjkbs));
		return gfxyTQnjsjkbs;
	}



	@Override
	public Double getTotalScore(GfxyTQnjsjkbs gfxyTQnjsjkbs) {

		double result = 0.0;
		int award = gfxyTQnjsjkbs.getAward();
		int classess = gfxyTQnjsjkbs.getClassess();
		if(classess == 1){
			if (award == 1) {
				result = 200;
            }else if (award == 2) {
                result = 150;
            }else if (award == 3) {
                result = 120;
            }else if (award == 4) {
                result = 100;
            }
		}else if (classess == 2) {
			if (award == 1) {
				result = 60;
			}else if (award == 2) {
				result = 50;
			}else if (award == 3) {
				result = 30;
			}else if (award == 4) {
				result = 20;
			}
		}else if (classess == 3) {
			if (award == 1) {
				result = 0.0;
			}else if (award == 2) {
				result = 15;
			}else if (award == 3) {
				result = 10;
			}else if (award == 4) {
				result = 5;
			}
		}
		return result;
	}

	@Override
	public IPage<GfxyTQnjsjkbsMenberPage> getGfxyTQnjsjkbsMemberPageListByYear(String date, Integer pageNo, Integer pageSize) {
		Page<GfxyTQnjsjkbsMenberPage> page = new Page<>(pageNo,pageSize);
		return page.setRecords(this.baseMapper.selectGfxyTQnjsjkbsMemberPageListByYear(date));
	}

	@Override
	public List<GfxyTQnjsjkbsMenberPage> getGfxyTQnjsjkbsMemberPageListByYear(String date) {
		return this.baseMapper.selectGfxyTQnjsjkbsMemberPageListByYear(date);
	}

	private int translateClassess(String name){
		if(name == null || name.equals("")){
			return 10000;
		} else if(name.equals("国家级")){
			return 1;
		} else if(name.equals("省级")){
			return 2;
		} else if(name.equals("校级")){
			return 3;
		} else {
			return 10000;
		}
	}
	private int translateAward(String award) {
		if(award == null || award.equals("")){
			return 10000;
		} else if(award.equals("特等奖")){
			return 1;
		} else if(award.equals("一等奖")){
			return 2;
		} else if(award.equals("二等奖")){
			return 3;
		} else if(award.equals("三等奖")){
			return 4;
		}
		return 10000;
	}

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(GfxyTQnjsjkbs qnjsjkbs)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(qnjsjkbs.getClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(GfxyTQnjsjkbsMenberPage.class, "classess", String.valueOf(qnjsjkbs.getClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		//奖项
		TeachingResultContent awardTeachingResultContent = new TeachingResultContent();
		awardTeachingResultContent.setType(1);
		awardTeachingResultContent.setLevel(qnjsjkbs.getAward());
		try {
			awardTeachingResultContent.setValue(dictTranslater.getDictValue(GfxyTQnjsjkbsMenberPage.class, "award", String.valueOf(qnjsjkbs.getAward())));
			result.add(awardTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		return result;
	}

}
